<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		mounted() {
			setInterval(t => {
				let token = uni.getStorageSync('token');
				if (!token) {
					return;
				}
				uni.$u.http.get(`${this.urlConfig.appServerPrefix}/pushHistory/list`, {
					header: {
						"token": token
					},
					params: {
						status: 0
					}
				}).then(res => {
					if (!res || !res.data || !res.data.extend || !res.data.extend.list || !res.data.extend
						.list.length) {
						return;
					}
					let list = res.data.extend.list;
					if (list.length === 1) {
						let pushHistory = list[0];
						let params = {
							inApp: true, // app内横幅提醒
							voice: true, // 声音提醒
							vibration: true, // 振动提醒
							messageType: pushHistory.templateTypeName,
							messageTitle: pushHistory.title,
							messageTime: pushHistory.messageTime,
							messageContent: pushHistory.shortContent,
							messageImage: `${this.urlConfig.oaPrefix}${pushHistory.imgUrl}`,
							closeTime: 10000,
							navigateUrl: `/pages/pushTemplate/pushTemplate?id=${pushHistory.pushTemplateId}`
						}
						this.$appPush(params)
					} else {
						let params = {
							inApp: true, // app内横幅提醒
							voice: true, // 声音提醒
							vibration: true, // 振动提醒
							messageType: "提醒",
							messageTitle: "有新消息",
							messageTime: "刚刚",
							messageContent: `您有${list.length}条新消息，请点击查看~`,
							messageImage: "/static/img/push_default_img.png",
							closeTime: 10000,
							tabUrl: "/pages/pushList/pushList"
						}
						this.$appPush(params)
					}
				}).catch(err => {
					console.log(err)
				});
			}, 20 * 1000)
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";
</style>
